#include "helper.h"
#include <sstream>

using namespace std;
void trim(std::string& str)
{	
	size_t i = 0;
	while(i < str.size() && isspace(str[i])) ++i;
	
	size_t j = str.size();
	while(j > 0 && isspace(str[j-1])) --j;

	str = str.substr(i, j-i);
}

string read_field_value(const string& content, const string& field)
{
	string value;
	istringstream iss;
	size_t pos = 0;

	pos = content.find(field);
	if(pos == string::npos)
		return string();

	iss.str(content.substr(pos, string::npos));
	getline(iss, value);

	pos = value.find('=');
	if(pos == string::npos)
		return string();

	value = value.substr(pos+1, string::npos);
	trim(value);
	return value;
}

